-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow linking against crates with #[no_std] -- reopening #7924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This has now changed significantly, such that it should warrant another review. The first commit has remained the same, but the second has changed.
|
// Only force linking the morestack library if segmented stacks are | ||
// requested. | ||
// | ||
// XXX: this should rather be a 3-way option: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this approach is what we decide on, I'll open an issue instead of committing an XXX
The |
@thestinger, I'm confused how that's relevant. If you inform the compiler that you don't want segmented stacks, then it's not an issue of "stack safety" but rather you're just responsible for allocating enough stack for the process. Things like tasks probably won't work, but if you're not using segmented stacks you're probably not using librustrt either. Things like C/C++ don't deal with this as far as I know. I thought they relied on the OS giving the initial thread enough stack space and then pthreads/whatever takes care of allocating stacks for spawned threads. At least in the context of something like a kernel, __morestack doesn't really make a lot of sense because that just indicates that everything should die. |
A stack overflow is a security vulnerability, whether or not you're able to grow the stack is a separate issue. Linux distributions have stack smashing protection for C in both user space and kernel space. It's not an absolute guarantee of protection, but it does catch almost all overflows. Right now Rust needs Ending the process, even if it means taking down the system, is the right thing to do when the alternative is a remote attacker being able to run a payload. |
Yes, stack overflow is a vulnerability, but is this really up to the compiler to set up these checks? This is a runtime issue, not a compiler issue. If you choose to not have librustrt/__morestack, then you're suddenly taking on the responsibility of the Rust as a language does not need __morestack; the current runtime requires __morestack, however. If you opt out of using the runtime, then you shouldn't be forced to use __morestack or segmented stacks at all. It seems to me that the same logic for rust requiring __morestack would apply just as well to C++/C requiring __morestack, which they don't. Sure you're exposing a "vulnerability", but you're also already treading in far more dangerous waters by opting out of the default runtime and most likely having lots of initial very unsafe code before transitioning to safe code. |
Rust as a language does need the C and C++ do use something like If we omit the |
If you do turn off stack overflow protection, all code would have to be in The above strategy should be automatic though, similar to how Windows does it but just for the safety aspect. |
Huh, I did not know that windows/linux had those enabled by default in the compilers. I looked into these and came up with:
If I'm right about linux (which I'm probably not...), then windows is the only platform to auto-grow the stack or place checks to make sure you're not growing it too much. On linux, a program like:
(when compiled without optimizations) just segfaults in calling memset because you can't push a return address. That was compiled on ubuntu and had the __stack_chk_fail function, but there's no protection for just growing the stack. If that were a rust function, in theory it would call __morestack (detecting it didn't have enough stack), and then allocate enough stack for itself. Basically, it still seems to me like there should be a way to turn off segmented stacks/__morestack. If rust wants to be a replacement for C in the systems language space, then there should be a way to turn them off because some environments may not want them at all. I think that there's also two things at play here. One is "I've run out of stack, can you automatically give me some more?" and the other is "Can you just tell me when I run out of stack?". Right now librustrt/__morestack implement the first, and this option of
I'm not entirely sure that we want 2 to be an option, because it sounds a lot like the user just being required to define __morestack instead of providing an implementation by default. In retrospect, this is quickly getting out of hand and should probably move to the mailing list. I think that there's a few things being discussed here and they're overlapping a bit. I'm going to think a bit more about these and maybe post something to the mailing list. |
@alexcrichton: What I mean by copying the Windows functionality is marking N guard pages and then having the compiler insert the If you didn't want segmented stacks, you could replace |
That's what I was intending by number 2 above. There's still the limitation that the stack limit has to be stored somewhere, and not only somewhere but exactly where LLVM is expecting it to be stored, so that's why I think that option 3 should still exist (to not emit this kind of code at all). Are you ok with those three options for emission of "segmented stack" code? I think that implementation-wise |
Previously having optional lang_items caused an assertion failure at compile-time, and then once that was fixed there was a segfault at runtime of using a NULL crate-map (crates with no_std)
I don't want this to rot, so I'm Dealing with a runtime-less rust should happen at a later time. |
This is a reopening of #7874